package com.tensquare.article.advice;

import com.tensquare.entity.Result;
import com.tensquare.entity.StatusCode;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLSyntaxErrorException;

@ControllerAdvice
public class BaseExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exception(Exception e) {
        if (e instanceof RedisConnectionFailureException) {
            return new Result(false, "Redis连接失败", StatusCode.ERROR);
        }else {
            e.printStackTrace();
        }
        return new Result(false, e.getMessage(), StatusCode.ERROR);
    }
}
